﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SalePartial.IDAL;
using DataLayerAgent;
using System.Data;
using SalePartial.Utility;
using SalePartial.Model;

namespace SalePartial.SQLServerDAL
{
    class XPCompanyCert : IXPCompanyCert
    {

        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid CertID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CertID", CertID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCompanyID(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsDeleteByCompanyID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCreateUserID(Guid CreateUserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsDeleteByCreateUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPCompanyCertInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("CertID", info.CertID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("CertType", info.CertType),
			new SqlParameter("CertName", info.CertName),
			new SqlParameter("CertFileName", info.CertFileName),
			new SqlParameter("CertFileContentType", info.CertFileContentType),
			new SqlParameter("CertFileSize", info.CertFileSize),
			new SqlParameter("CertFileData", info.CertFileData),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("LastUpdateDate", info.LastUpdateDate),
			new SqlParameter("ModerateUserID", info.ModerateUserID),
			new SqlParameter("ModerateStatus", info.ModerateStatus),
			new SqlParameter("ModerateDate", info.ModerateDate),
			new SqlParameter("Comments", info.Comments)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectAll]", parameters, "XPCompanyCert_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectByCompanyID]", parameters, "XPCompanyCert_ByCompanyID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByCreateUserID(Guid CreateUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectByCreateUserID]", parameters, "XPCompanyCert_ByCreateUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectDynamic]", parameters, "XPCompanyCert_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectPaged]", parameters, "XPCompanyCert_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid CertID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CertID", CertID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertSelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectByCompanyID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByCreateUserID(Guid CreateUserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CreateUserID", CreateUserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertsSelectByCreateUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid CertID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CertID", CertID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertSelect]", parameters, "XPCompanyCert_Single");
            DataTable dt = ds.Tables["XPCompanyCert_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPCompanyCertInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("CertID", info.CertID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("CertType", info.CertType),
			new SqlParameter("CertName", info.CertName),
			new SqlParameter("CertFileName", info.CertFileName),
			new SqlParameter("CertFileContentType", info.CertFileContentType),
			new SqlParameter("CertFileSize", info.CertFileSize),
			new SqlParameter("CertFileData", info.CertFileData),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("LastUpdateDate", info.LastUpdateDate),
			new SqlParameter("ModerateUserID",info.ModerateUserID),
			new SqlParameter("ModerateStatus", info.ModerateStatus),
			new SqlParameter("ModerateDate", info.ModerateDate),
			new SqlParameter("Comments", info.Comments)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyCertUpdate]", parameters, RowsAffected);
        }
    }
}
